package br.com.jomos.aQuery 
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	/**
	 * ...
	 * @author Jomos
	 */
	public class Selector
	{
		
		public var selected:*;

		private var ccc:int = 0;
		
		public function Selector(d:*)
		{
			selected = d;
		}
		
		public function children(c:Class = null):Selector
		{
			var resultArray:Array;
			var tempArray:Array;
			if (selected as Array)
			{
				for each(var d in selected)
				{
					tempArray = _getChildrens(d,c);
					
					if (!resultArray || resultArray.length == 0) resultArray = tempArray;
					else {
						resultArray = resultArray.concat(tempArray);
					}
				}
			} else {
				resultArray = _getChildrens(selected,c);
			}
			
			Selector(this).selected = resultArray;

			return Selector(this);
		}
		
		private function _getChildrens(d:DisplayObjectContainer,c:Class):Array
		{

			var resultArray:Array = new Array();
			var tempChild:*;
			for (var k:int = 0; k < d.numChildren; k++)
			{
				tempChild = d.getChildAt(k);
				if (c && !(tempChild as c)) continue;
				else resultArray.push(d.getChildAt(k));
			}
			
			return resultArray;
		}
		
	}

}